package com.jiangxjsy.authorization.client;

import com.jiangxjsy.core.wrap.Result;
import com.jiangxjsy.core.wrap.ResultBuilder;
import com.jiangxjsy.core.wrap.ResultCode;
import com.jiangxjsy.model.authorization.bo.AdminUserStatusBO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.List;

/**
 * wukong-crm-master
 * 蒋胜宇
 * 2025/6/4 14:48
 */

@FeignClient(name = "admin", fallback = AdminUserClient.AdminUserClientFallback.class)
public interface AdminUserClient {
    /**
     * 通过用户名查询用户
     *
     * @param username 用户名
     * @return Result
     */
    @RequestMapping(value = "/adminUser/findByUsername")
    Result<?> findByUsername(@RequestParam("username") String username);

    /**
     * 通过用户 ID 查询没有权限的菜单
     *
     * @param userId 用户 ID
     * @return Result
     */
    @PostMapping(value = "/adminRole/queryNoAuthMenu")
    Result<List<String>> queryNoAuthMenu(@RequestParam("userId") Long userId);

    /**
     * 通过用户 ID 查询用户角色 ID 列表
     *
     * @param userId 用户 ID
     * @return Result
     */
    @RequestMapping(value = "/adminUser/queryUserRoleIds")
    Result<List<Integer>> queryUserRoleIds(@RequestParam("userId") Long userId);

    /**
     * 设置用户状态
     *
     * @param adminUserStatusBO 用户状态 BO 对象
     * @return Result
     */
    @PostMapping("/adminUser/setUserStatus")
    Result<?> setUserStatus(@RequestBody AdminUserStatusBO adminUserStatusBO);

    /**
     * 激活用户
     *
     * @param adminUserStatusBO 用户状态 BO 对象
     * @return Result
     */
    @PostMapping("/adminUser/activateUser")
    Result<?> activateUser(@RequestBody AdminUserStatusBO adminUserStatusBO);


    @Component
    class AdminUserClientFallback implements AdminUserClient {
        /**
         * 通过用户名查询用户
         *
         * @param username 用户名
         * @return Result
         */
        @Override
        public Result<?> findByUsername(String username) {
            return ResultBuilder.error(ResultCode.SystemResultCode.SYSTEM_NO_FOUND);
        }

        /**
         * 通过用户 ID 查询没有权限的菜单
         *
         * @param userId 用户 ID
         * @return Result
         */
        @Override
        public Result<List<String>> queryNoAuthMenu(Long userId) {
            return ResultBuilder.error(ResultCode.SystemResultCode.SYSTEM_NO_FOUND);
        }

        /**
         * 通过用户 ID 查询用户角色 ID 列表
         *
         * @param userId 用户 ID
         * @return Result
         */
        @Override
        public Result<List<Integer>> queryUserRoleIds(Long userId) {
            return ResultBuilder.ok(new ArrayList<>());
        }

        /**
         * 设置用户状态
         *
         * @param adminUserStatusBO 用户状态 BO 对象
         * @return Result
         */
        @Override
        public Result<?> setUserStatus(AdminUserStatusBO adminUserStatusBO) {
            return ResultBuilder.ok();
        }

        /**
         * 激活用户
         *
         * @param adminUserStatusBO 用户状态 BO 对象
         * @return Result
         */
        @Override
        public Result<?> activateUser(AdminUserStatusBO adminUserStatusBO) {
            return ResultBuilder.ok();
        }
    }
}
